<template>
	<view class="add">
		<view class="box">
			<u-field v-model="dataForm.name" label="仓库名称" required placeholder="请填写仓库名称">
			</u-field>
			<u-field v-model="dataForm.number" label="仓库编号" required placeholder="请填写仓库编号">
			</u-field>
			<u-field v-model="dataForm.address" label="仓库地址" required placeholder="请填写仓库地址">
			</u-field>
		</view>
		<view class="staus">
			<u-field label="仓库状态" disabled >
				<view class="" slot='right'>
					<u-switch v-model="dataForm.status"></u-switch>
				</view>
			</u-field>
		</view>
		<view class="btn" @click="submit">确定添加</view>
	</view>
</template>

<script>
	import {AddNewData,UpdateModifyData} from '@/common/http.request.js'
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		data(){
			return{
				index:'',
				dataForm:{
					name:'',
					number:'',
					address:'',
					status:false
				}
			}
		},
		computed: {
			...mapState(['vuex_adminuser'])
		},
		onLoad(options){
			if(options.index){
				this.index = options.index
				let page = getCurrentPages()
				let currentPage = page[page.length-2]
				// console.log(currentPage.$vm.dataList[options.index])
				this.dataForm = currentPage.$vm.dataList[options.index]
				this.dataForm.status= this.dataForm.status == 1?true:false
			}
		},
		methods:{
			submit(){
				if(!this.dataForm.name){
					return this.$toast('仓库名称不能为空')
				}else if(!this.dataForm.number){
					return this.$toast('仓库编号不能为空')
				}else if(!this.dataForm.address){
					return this.$toast('仓库地址不能为空')
				}
				this.dataForm.status = this.dataForm.status ==true?1:0
				if(this.index){
					UpdateModifyData('e_product_warehouse',{...this.dataForm}).then(res=>{
						this.uniBack(1)
					})
				}else{
					this.dataForm.fk_business_id = this.vuex_adminuser.pk_id
					AddNewData('e_product_warehouse',{...this.dataForm}).then(res=>{
						this.uniBack(1)
					})
				}
			}
		}
	}
</script>
<style>
	page{
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
.add{
	.box{
		background-color: #fff;
		margin-bottom: 20rpx;
	}
	.staus{
		background-color: #fff;
	}
	.btn{
		margin: 0 40rpx;
		width: 90%;
		background-color: #3297ef;
		color: #fff;
		text-align: center;
		line-height: 80rpx;
		border-radius: 10rpx;
		margin-top: 140rpx;
	}
}
</style>
